const vscode = require('vscode');
const i18next = require('i18next');
const fs = require('fs');
const path = require('path');
const MenuItemProvider = require('../src/view/menu/menuItemProvider');
const CommonApi = require('../src/command/registerCommand');

const hiSmartLiteEx = require('./hiSmartLiteEx');
exports.activate = async function (context) {
  try {
    const packageEn = path.resolve(__filename, '../../package.nls.json');
    const packageCn = path.resolve(__filename, '../../package.nls.zh-cn.json');
    await hiSmartLiteEx.initHiSmartLiteEx(context);
    const translationCN = fs.readFileSync(packageCn);
    const translationEN = fs.readFileSync(packageEn);
    const resources = {
      en: {
        translation: JSON.parse(translationEN),
      },
      zh: {
        translation: JSON.parse(translationCN)
      }
    };
    i18next.init({
      resources,
      fallbackLng: vscode.env.language
    });
    // 激活册成功, 打印消息
    console.log('congratulations, your extension "HiSmartLite Foundation is now active');
    // 注册命令
    new CommonApi(context).register();
    // 初始化左侧导航栏
    new MenuItemProvider().initMenu();
  } catch (error) {
    console.error('active error:', error);
  }
};

exports.deactivate = function deactivate() {
  console.log('your extension "HiSmartLite Foundation" is now deactive');
};